package com.example;

import org.json.JSONObject;
import org.json.JSONArray;

public class OpenWeatherMapParser implements WeatherDataParser {
    @Override
    public WeatherData parse(String jsonData) {
        JSONObject json = new JSONObject(jsonData);
        
        String location = json.getString("name");
        JSONObject main = json.getJSONObject("main");
        double temp = main.getDouble("temp");
        double feelsLike = main.getDouble("feels_like");
        int humidity = main.getInt("humidity");
        
        JSONObject wind = json.getJSONObject("wind");
        double windSpeed = wind.getDouble("speed");
        
        JSONArray weatherArray = json.getJSONArray("weather");
        JSONObject weather = weatherArray.getJSONObject(0);
        String description = weather.getString("description");
        String iconCode = weather.getString("icon");
        
        return new WeatherData(location, temp, feelsLike, humidity, windSpeed, description, iconCode);
    }
}